package com.d0318;

import java.util.Date;

public class JoinTester implements Runnable {
    String name;
    public JoinTester(){}
    public JoinTester(String name){
        this.name=name;
    }

    @Override
    public void run() {
        System.out.println(name+"线程开始于:"+new Date());
        try {
            Thread.sleep(3000);
            if (this.name=="Two"){
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name+"线程结束于:"+new Date());
    }

    public static void main(String[] args) {
        JoinTester joinTester1=new JoinTester("One");
        JoinTester joinTester2=new JoinTester("Two");
        Thread thread1=new Thread(joinTester1);
        Thread thread2=new Thread(joinTester2);
        thread1.start();
        thread2.start();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程结束");
    }
}
